<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: Commands::Discover</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">Commands::Discover</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../files/vendor/rails/railties/lib/commands/plugin_rb.html">
                vendor/rails/railties/lib/commands/plugin.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                <a href="../Object.html">
                Object
               </a>
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M002270">extract_repository_uri</a>&nbsp;&nbsp;
      <a href="#M002266">new</a>&nbsp;&nbsp;
      <a href="#M002267">options</a>&nbsp;&nbsp;
      <a href="#M002268">parse!</a>&nbsp;&nbsp;
      <a href="#M002269">scrape</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M002266" class="method-detail">
        <a name="M002266"></a>

        <div class="method-heading">
          <a href="#M002266" class="method-signature">
          <span class="method-name">new</span><span class="method-args">(base_command)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M002266-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M002266-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/railties/lib/commands/plugin.rb, line 678</span>
678:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">base_command</span>)
679:       <span class="ruby-ivar">@base_command</span> = <span class="ruby-identifier">base_command</span>
680:       <span class="ruby-ivar">@list</span> = <span class="ruby-keyword kw">false</span>
681:       <span class="ruby-ivar">@prompt</span> = <span class="ruby-keyword kw">true</span>
682:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M002270" class="method-detail">
        <a name="M002270"></a>

        <div class="method-heading">
          <a href="#M002270" class="method-signature">
          <span class="method-name">extract_repository_uri</span><span class="method-args">(uri)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M002270-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M002270-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/railties/lib/commands/plugin.rb, line 745</span>
745:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">extract_repository_uri</span>(<span class="ruby-identifier">uri</span>)
746:       <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">match</span>(<span class="ruby-regexp re">/(svn|https?):.*\/plugins\//i</span>)[<span class="ruby-value">0</span>]
747:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M002267" class="method-detail">
        <a name="M002267"></a>

        <div class="method-heading">
          <a href="#M002267" class="method-signature">
          <span class="method-name">options</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M002267-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M002267-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/railties/lib/commands/plugin.rb, line 684</span>
684:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">options</span>
685:       <span class="ruby-constant">OptionParser</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">o</span><span class="ruby-operator">|</span>
686:         <span class="ruby-identifier">o</span>.<span class="ruby-identifier">set_summary_indent</span>(<span class="ruby-value str">'  '</span>)
687:         <span class="ruby-identifier">o</span>.<span class="ruby-identifier">banner</span> =    <span class="ruby-node">&quot;Usage: #{@base_command.script_name} discover URI [URI [URI]...]&quot;</span>
688:         <span class="ruby-identifier">o</span>.<span class="ruby-identifier">define_head</span> <span class="ruby-value str">&quot;Discover repositories referenced on a page.&quot;</span>
689:         <span class="ruby-identifier">o</span>.<span class="ruby-identifier">separator</span>   <span class="ruby-value str">&quot;&quot;</span>        
690:         <span class="ruby-identifier">o</span>.<span class="ruby-identifier">separator</span>   <span class="ruby-value str">&quot;Options:&quot;</span>
691:         <span class="ruby-identifier">o</span>.<span class="ruby-identifier">separator</span>   <span class="ruby-value str">&quot;&quot;</span>
692:         <span class="ruby-identifier">o</span>.<span class="ruby-identifier">on</span>(         <span class="ruby-value str">&quot;-l&quot;</span>, <span class="ruby-value str">&quot;--list&quot;</span>, 
693:                       <span class="ruby-value str">&quot;List but don't prompt or add discovered repositories.&quot;</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">list</span><span class="ruby-operator">|</span> <span class="ruby-ivar">@list</span>, <span class="ruby-ivar">@prompt</span> = <span class="ruby-identifier">list</span>, <span class="ruby-operator">!</span><span class="ruby-ivar">@list</span> }
694:         <span class="ruby-identifier">o</span>.<span class="ruby-identifier">on</span>(         <span class="ruby-value str">&quot;-n&quot;</span>, <span class="ruby-value str">&quot;--no-prompt&quot;</span>, 
695:                       <span class="ruby-value str">&quot;Add all new repositories without prompting.&quot;</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">v</span><span class="ruby-operator">|</span> <span class="ruby-ivar">@prompt</span> = <span class="ruby-operator">!</span><span class="ruby-identifier">v</span> }
696:       <span class="ruby-keyword kw">end</span>
697:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M002268" class="method-detail">
        <a name="M002268"></a>

        <div class="method-heading">
          <a href="#M002268" class="method-signature">
          <span class="method-name">parse!</span><span class="method-args">(args)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M002268-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M002268-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/railties/lib/commands/plugin.rb, line 699</span>
699:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">parse!</span>(<span class="ruby-identifier">args</span>)
700:       <span class="ruby-identifier">options</span>.<span class="ruby-identifier">parse!</span>(<span class="ruby-identifier">args</span>)
701:       <span class="ruby-identifier">args</span> = [<span class="ruby-value str">'http://wiki.rubyonrails.org/rails/pages/Plugins'</span>] <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">empty?</span>
702:       <span class="ruby-identifier">args</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">uri</span><span class="ruby-operator">|</span>
703:         <span class="ruby-identifier">scrape</span>(<span class="ruby-identifier">uri</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">repo_uri</span><span class="ruby-operator">|</span>
704:           <span class="ruby-identifier">catch</span>(<span class="ruby-identifier">:next_uri</span>) <span class="ruby-keyword kw">do</span>
705:             <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@prompt</span>
706:               <span class="ruby-keyword kw">begin</span>
707:                 <span class="ruby-identifier">$stdout</span>.<span class="ruby-identifier">print</span> <span class="ruby-node">&quot;Add #{repo_uri}? [Y/n] &quot;</span>
708:                 <span class="ruby-identifier">throw</span> <span class="ruby-identifier">:next_uri</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">$stdin</span>.<span class="ruby-identifier">gets</span> <span class="ruby-operator">!~</span> <span class="ruby-regexp re">/^y?$/i</span>
709:               <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Interrupt</span>
710:                 <span class="ruby-identifier">$stdout</span>.<span class="ruby-identifier">puts</span>
711:                 <span class="ruby-identifier">exit</span> <span class="ruby-value">1</span>
712:               <span class="ruby-keyword kw">end</span>
713:             <span class="ruby-keyword kw">elsif</span> <span class="ruby-ivar">@list</span>
714:               <span class="ruby-identifier">puts</span> <span class="ruby-identifier">repo_uri</span>
715:               <span class="ruby-identifier">throw</span> <span class="ruby-identifier">:next_uri</span>
716:             <span class="ruby-keyword kw">end</span>
717:             <span class="ruby-constant">Repositories</span>.<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">add</span>(<span class="ruby-identifier">repo_uri</span>)
718:             <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;discovered: #{repo_uri}&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">$verbose</span> <span class="ruby-keyword kw">or</span> <span class="ruby-operator">!</span><span class="ruby-ivar">@prompt</span>
719:           <span class="ruby-keyword kw">end</span>
720:         <span class="ruby-keyword kw">end</span>
721:       <span class="ruby-keyword kw">end</span>
722:       <span class="ruby-constant">Repositories</span>.<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">save</span>
723:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M002269" class="method-detail">
        <a name="M002269"></a>

        <div class="method-heading">
          <a href="#M002269" class="method-signature">
          <span class="method-name">scrape</span><span class="method-args">(uri) {|uri unless dupes.include?(uri) || Repositories.instance.exist?(uri)| ...}</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M002269-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M002269-source">
<pre>
     <span class="ruby-comment cmt"># File vendor/rails/railties/lib/commands/plugin.rb, line 725</span>
725:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">scrape</span>(<span class="ruby-identifier">uri</span>)
726:       <span class="ruby-identifier">require</span> <span class="ruby-value str">'open-uri'</span>
727:       <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Scraping #{uri}&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">$verbose</span>
728:       <span class="ruby-identifier">dupes</span> = []
729:       <span class="ruby-identifier">content</span> = <span class="ruby-identifier">open</span>(<span class="ruby-identifier">uri</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">line</span><span class="ruby-operator">|</span>
730:         <span class="ruby-keyword kw">begin</span>
731:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">line</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/&lt;a[^&gt;]*href=['&quot;]([^'&quot;]*)['&quot;]/</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">line</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/(svn:\/\/[^&lt;|\n]*)/</span>
732:             <span class="ruby-identifier">uri</span> = <span class="ruby-identifier">$1</span>
733:             <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">uri</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^\w+:\/\//</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">uri</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/\/plugins\//</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">uri</span> <span class="ruby-operator">!~</span> <span class="ruby-regexp re">/\/browser\//</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">uri</span> <span class="ruby-operator">!~</span> <span class="ruby-regexp re">/^http:\/\/wiki\.rubyonrails/</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">uri</span> <span class="ruby-operator">!~</span> <span class="ruby-regexp re">/http:\/\/instiki/</span>
734:               <span class="ruby-identifier">uri</span> = <span class="ruby-identifier">extract_repository_uri</span>(<span class="ruby-identifier">uri</span>)
735:               <span class="ruby-keyword kw">yield</span> <span class="ruby-identifier">uri</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">dupes</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">uri</span>) <span class="ruby-operator">||</span> <span class="ruby-constant">Repositories</span>.<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">exist?</span>(<span class="ruby-identifier">uri</span>)
736:               <span class="ruby-identifier">dupes</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">uri</span>
737:             <span class="ruby-keyword kw">end</span>
738:           <span class="ruby-keyword kw">end</span>
739:         <span class="ruby-keyword kw">rescue</span>
740:           <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Problems scraping '#{uri}': #{$!.to_s}&quot;</span>
741:         <span class="ruby-keyword kw">end</span>
742:       <span class="ruby-keyword kw">end</span>
743:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>